using CustomLitJson;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;

public class LocalizationDriver
{

    public static void Load()
    {
        var nameList = new List<string>() { "localization_prefab", "localization_code" };
        foreach (var name in nameList)
        {
            var asset = Resources.Load<TextAsset>(name);
            if(asset == null)
            {
                continue;
            }
            var json = asset.text;
            var keyToRowDic = JsonMapper.Instance.ToObject<Dictionary<string, Row>>(json);
            //Debug.Log("[LocalizationDriver] json: " + json + ", keyToRowDic: " + keyToRowDic);
            foreach (var kv in keyToRowDic)
            {
                var key = kv.Key;
                var row = kv.Value;
                if (row != null)
                {
                    AddToLocalization(row);
                }
            }
        }
        LocalizerManager.Stuff.SetDataLoaded();

    }

    static void AddToLocalization(Row row)
    {
        var key = row.key;
        LocalizationManager.Stuff.Add("cn", key, row.cn);
        LocalizationManager.Stuff.Add("en", key, row.en);
        LocalizationManager.Stuff.Add("tw", key, row.tw);
    }

    public class Row
    {
        public string key;
        public string cn;
        public string en;
        public string tw;
    }
}
